import { request } from "@/utils/service"
import type * as Admin from "./types/admin"

/** 增 */
export function addAdminDataApi(data: Admin.IAddAdminRequestData) {
  return request({
    url: "admin/addOne",
    method: "post",
    data
  })
}

/** 删 */
export function deleteAdminDataApi(id: number) {
  return request({
    url: `admin/deleteOne`,
    method: "delete",
    params: { id }
  })
}

/** 改 */
export function updateAdminDataApi(data: Admin.IUpdateAdminequestData) {
  return request({
    url: "admin/updateOne",
    method: "put",
    data
  })
}

/** 查 */
export function getAdminDataApi(params: Admin.IGetAdminRequestData) {
  return request<Admin.GetAdminResponseData>({
    url: "admin/getList",
    method: "get",
    params
  })
}

export function getAdminByNameDataApi(params: { name: string; departmentId: number | undefined }) {
  return request<Admin.GetAdminByNameResponseData>({
    url: "admin/getIdAndName",
    method: "get",
    params
  })
}

/**
 * 获取验证码
 * @param username
 * @returns
 */
export function getCodeApi() {
  return request<{ blob: Blob }>({
    url: "captcha/image",
    responseType: "blob",
    method: "get"
  })
}

export function updateOneselfApi(data: { id: number; personalPhone: string; officialPhone: string }) {
  return request<{ blob: Blob }>({
    url: "admin/updateOneself",
    method: "put",
    data
  })
}

export function getPersonalInfoApi() {
  return request<Admin.GetPersonalInfoResponseData>({
    url: "admin/getPersonalInfo"
  })
}

export function checkLoginStatus() {
  return request<IApiResponseData<null>>({
    url: "isLogin",
    method: "get"
  })
}

export function disableAccountApi(username: string) {
  return request<IApiResponseData<null>>({
    url: "admin/disableAccount",
    method: "put",
    params: {
      username
    }
  })
}

export function enableAccountApi(username: string) {
  return request<IApiResponseData<null>>({
    url: "admin/enableAccount",
    method: "put",
    params: {
      username
    }
  })
}
